# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/15 21:32
# @Author   : Robot-Zsj
"""
description:

i:
10 2 4

o:
2
"""
import pdb

k, n, m = map(int, input().split())


def getResult():
    global k

    if n >= m:
        return 0

    count = 0

    while k > 0:
        pdb.set_trace()
        remain = k % m
        if remain == n:
            count += 1
        k //= m
    return count

print(getResult())
